# Contributor: Peter Bui <pnutzh4x0r@gmail.com>
# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Contributor: Timo Teräs <timo.teras@iki.fi>
# Contributor: Leo <thinkabit.ukim@gmail.com>
# Contributor: Sodface <sod@sodface.com>
# Maintainer: lauren n. liberda <lauren@selfisekai.rocks>
pkgname=yt-dlp
pkgver=2024.04.09
pkgrel=1
pkgdesc="Command-line program to download videos from YouTube"
url="https://github.com/yt-dlp/yt-dlp"
arch="noarch"
license="Unlicense"
depends="python3"
_extradeps="
	attr
	ca-certificates
	ffmpeg
	py3-brotli
	py3-mutagen
	py3-pycryptodomex
	py3-secretstorage
	py3-websockets
	"
makedepends="$_extradeps py3-gpep517 py3-hatchling"
checkdepends="
	py3-flake8
	py3-nose
	py3-pytest-xdist
	py3-requests
	"
subpackages="
	$pkgname-core-pyc
	$pkgname-core
	$pkgname-doc
	$pkgname-zsh-completion
	$pkgname-bash-completion
	$pkgname-fish-completion
	"
[ "$CARCH" != 'riscv64' ] || options="!check"
source="$pkgname-$pkgver.tar.gz::https://github.com/yt-dlp/yt-dlp/releases/download/$pkgver/yt-dlp.tar.gz
	"
builddir="$srcdir/$pkgname"

# secfixes:
#   2023.11.14-r0:
#     - CVE-2023-46121
#   2023.07.06-r0:
#     - CVE-2023-35934
#   0-r0:
#     - CVE-2023-40581
#     - CVE-2024-22423

build() {
	gpep517 build-wheel \
		--wheel-dir .dist \
		--output-fd 3 3>&1 >&2
}

check() {
	python3 -m venv --clear --without-pip --system-site-packages .testenv
	.testenv/bin/python3 -m installer .dist/*.whl
	# last 2 are flaky in upstream, failing more often than not here
	.testenv/bin/python3 -m pytest -k 'not download and not verify_cert and not mtls'
}

package() {
	depends="
		$_extradeps
		yt-dlp-core=$pkgver-r$pkgrel
		"

	python3 -m installer -d "$pkgdir" \
		.dist/*.whl

	ln -sfv yt-dlp "$pkgdir"/usr/bin/youtube-dl
}

core() {
	# provide compat for removed old youtube-dl
	provides="youtube-dl=$pkgver-r$pkgrel"
	replaces="youtube-dl"

	amove usr/lib/python3*/site-packages/
	amove usr/bin
}

sha512sums="
5eada1c6a3d656c4f70552824a59ed677ecc102e1a2c3475a12fccff78ea267d7391e778060d708bf0aca1bdf92f4bf413785e0cd65b43259535577e92755556  yt-dlp-2024.04.09.tar.gz
"
